home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / xpcom / xptcall.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  9KB  |  223 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1999
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  26.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. /* Public declarations for xptcall. */
  39.  
  40. #ifndef xptcall_h___
  41. #define xptcall_h___
  42.  
  43. #include "prtypes.h"
  44. #include "nscore.h"
  45. #include "nsISupports.h"
  46. #include "xpt_struct.h"
  47. #include "xptinfo.h"
  48. #include "nsIInterfaceInfo.h"
  49.  
  50. /***************************************************************************/
  51. /*
  52.  * The linkage of XPTC API functions differs depending on whether the file is
  53.  * used within the XPTC library or not.  Any source file within the XPTC
  54.  * library should define EXPORT_XPTC_API whereas any client of the library
  55.  * should not.
  56.  */
  57. #ifdef EXPORT_XPTC_API
  58. # define XPTC_PUBLIC_API(t)   PR_IMPLEMENT(t)
  59. # define XPTC_PUBLIC_DATA(t)  PR_IMPLEMENT_DATA(t)
  60. # define XPTC_EXPORT          NS_EXPORT
  61. #else
  62. # define XPTC_PUBLIC_API(t)   NS_IMPORT t
  63. # define XPTC_PUBLIC_DATA(t)  NS_IMPORT t
  64. # define XPTC_EXPORT          NS_IMPORT
  65. #endif
  66. #define XPTC_FRIEND_API(t)    XPTC_PUBLIC_API(t)
  67. #define XPTC_FRIEND_DATA(t)   XPTC_PUBLIC_DATA(t)
  68. /***************************************************************************/
  69.  
  70. struct nsXPTCMiniVariant
  71. {
  72. // No ctors or dtors so that we can use arrays of these on the stack
  73. // with no penalty.
  74.     union
  75.     {
  76.         PRInt8    i8;
  77.         PRInt16   i16;
  78.         PRInt32   i32;
  79.         PRInt64   i64;
  80.         PRUint8   u8;
  81.         PRUint16  u16;
  82.         PRUint32  u32;
  83.         PRUint64  u64;
  84.         float     f;
  85.         double    d;
  86.         PRBool    b;
  87.         char      c;
  88.         PRUnichar wc;
  89.         void*     p;
  90.     } val;
  91. };
  92.  
  93. struct nsXPTCVariant : public nsXPTCMiniVariant
  94. {
  95. // No ctors or dtors so that we can use arrays of these on the stack
  96. // with no penalty.
  97.  
  98.     // inherits 'val' here
  99.     void*     ptr;
  100.     nsXPTType type;
  101.     PRUint8   flags;
  102.  
  103.     enum
  104.     {
  105.         // these are bitflags!
  106.         PTR_IS_DATA    = 0x1,  // ptr points to 'real' data in val
  107.         VAL_IS_ALLOCD  = 0x2,  // val.p holds alloc'd ptr that must be freed
  108.         VAL_IS_IFACE   = 0x4,  // val.p holds interface ptr that must be released
  109.         VAL_IS_ARRAY   = 0x8,  // val.p holds a pointer to an array needing cleanup
  110.         VAL_IS_DOMSTR  = 0x10, // val.p holds a pointer to domstring needing cleanup
  111.         VAL_IS_UTF8STR = 0x20, // val.p holds a pointer to utf8string needing cleanup
  112.         VAL_IS_CSTR    = 0x40  // val.p holds a pointer to cstring needing cleanup        
  113.     };
  114.  
  115.     void ClearFlags()         {flags = 0;}
  116.     void SetPtrIsData()       {flags |= PTR_IS_DATA;}
  117.     void SetValIsAllocated()  {flags |= VAL_IS_ALLOCD;}
  118.     void SetValIsInterface()  {flags |= VAL_IS_IFACE;}
  119.     void SetValIsArray()      {flags |= VAL_IS_ARRAY;}
  120.     void SetValIsDOMString()  {flags |= VAL_IS_DOMSTR;}
  121.     void SetValIsUTF8String() {flags |= VAL_IS_UTF8STR;}
  122.     void SetValIsCString()    {flags |= VAL_IS_CSTR;}    
  123.  
  124.     PRBool IsPtrData()       const  {return 0 != (flags & PTR_IS_DATA);}
  125.     PRBool IsValAllocated()  const  {return 0 != (flags & VAL_IS_ALLOCD);}
  126.     PRBool IsValInterface()  const  {return 0 != (flags & VAL_IS_IFACE);}
  127.     PRBool IsValArray()      const  {return 0 != (flags & VAL_IS_ARRAY);}
  128.     PRBool IsValDOMString()  const  {return 0 != (flags & VAL_IS_DOMSTR);}
  129.     PRBool IsValUTF8String() const  {return 0 != (flags & VAL_IS_UTF8STR);}
  130.     PRBool IsValCString()    const  {return 0 != (flags & VAL_IS_CSTR);}    
  131.  
  132.     void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, PRUint8 f)
  133.     {
  134.         type = t;
  135.         flags = f;
  136.  
  137.         if(f & PTR_IS_DATA)
  138.         {
  139.             ptr = mv.val.p;
  140.             val.p = nsnull;
  141.         }
  142.         else
  143.         {
  144.             ptr = nsnull;
  145.             switch(t.TagPart()) {
  146.               case nsXPTType::T_I8:                val.i8  = mv.val.i8;  break;
  147.               case nsXPTType::T_I16:               val.i16 = mv.val.i16; break;
  148.               case nsXPTType::T_I32:               val.i32 = mv.val.i32; break;
  149.               case nsXPTType::T_I64:               val.i64 = mv.val.i64; break;
  150.               case nsXPTType::T_U8:                val.u8  = mv.val.u8;  break;
  151.               case nsXPTType::T_U16:               val.u16 = mv.val.u16; break;
  152.               case nsXPTType::T_U32:               val.u32 = mv.val.u32; break;
  153.               case nsXPTType::T_U64:               val.u64 = mv.val.u64; break;
  154.               case nsXPTType::T_FLOAT:             val.f   = mv.val.f;   break;
  155.               case nsXPTType::T_DOUBLE:            val.d   = mv.val.d;   break;
  156.               case nsXPTType::T_BOOL:              val.b   = mv.val.b;   break;
  157.               case nsXPTType::T_CHAR:              val.c   = mv.val.c;   break;
  158.               case nsXPTType::T_WCHAR:             val.wc  = mv.val.wc;  break;
  159.               case nsXPTType::T_VOID:              /* fall through */
  160.               case nsXPTType::T_IID:               /* fall through */
  161.               case nsXPTType::T_DOMSTRING:         /* fall through */
  162.               case nsXPTType::T_CHAR_STR:          /* fall through */
  163.               case nsXPTType::T_WCHAR_STR:         /* fall through */
  164.               case nsXPTType::T_INTERFACE:         /* fall through */
  165.               case nsXPTType::T_INTERFACE_IS:      /* fall through */
  166.               case nsXPTType::T_ARRAY:             /* fall through */
  167.               case nsXPTType::T_PSTRING_SIZE_IS:   /* fall through */
  168.               case nsXPTType::T_PWSTRING_SIZE_IS:  /* fall through */
  169.               case nsXPTType::T_UTF8STRING:        /* fall through */
  170.               case nsXPTType::T_CSTRING:           /* fall through */              
  171.               default:                             val.p   = mv.val.p;   break;
  172.             }
  173.         }
  174.     }
  175. };
  176.  
  177. /***************************************************************************/
  178.  
  179. #undef  IMETHOD_VISIBILITY
  180. #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
  181.  
  182. class XPTC_EXPORT nsXPTCStubBase : public nsISupports
  183. {
  184. public:
  185.     // We are going to implement this to force the compiler to generate a 
  186.     // vtbl for this class. Since this is overridden in the inheriting class
  187.     // we expect it to never be called. 
  188.     // *This is needed by the Irix implementation.*
  189.     NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
  190.  
  191.     // Include generated vtbl stub declarations.
  192.     // These are virtual and *also* implemented by this class..
  193. #include "xptcstubsdecl.inc"
  194.  
  195.     // The following methods must be provided by inheritor of this class.
  196.  
  197.     // return a refcounted pointer to the InterfaceInfo for this object
  198.     // NOTE: on some platforms this MUST not fail or we crash!
  199.     NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
  200.  
  201.     // call this method and return result
  202.     NS_IMETHOD CallMethod(PRUint16 methodIndex,
  203.                           const nsXPTMethodInfo* info,
  204.                           nsXPTCMiniVariant* params) = 0;
  205. };
  206.  
  207. #undef  IMETHOD_VISIBILITY
  208. #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
  209.  
  210. PR_BEGIN_EXTERN_C
  211.  
  212. XPTC_PUBLIC_API(nsresult)
  213. XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
  214.                    PRUint32 paramCount, nsXPTCVariant* params);
  215.  
  216. // Used to force linking of these obj for the static library into the dll
  217. extern void xptc_dummy();
  218. extern void xptc_dummy2();
  219.  
  220. PR_END_EXTERN_C
  221.  
  222. #endif /* xptcall_h___ */
  223.